package com.teira.rhrrealstate.entity;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.security.management.UserPassword;
import org.jboss.seam.annotations.security.management.UserPrincipal;
import org.jboss.seam.annotations.security.management.UserRoles;

@Entity
@Name("usuario")
@Scope(ScopeType.SESSION)
@Table(name="usuario")
public class Usuario implements Serializable
{
	  private Integer userId;

	  private String username;

	  private String passwordHash;

	  private Set<Rol> roles;

	  

	  @Id 
	  @SequenceGenerator(name="my_seq", sequenceName="USUARIO_SEQ")
	  @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="my_seq")
	  public Integer getUserId() { return userId; }

	  public void setUserId(Integer userId) { this.userId = userId; }

	  

	  @UserPrincipal
	  public String getUsername() { return username; }
	  public void setUsername(String username) { this.username = username; }

	  

	  @UserPassword
	  public String getPasswordHash() { return passwordHash; }
	  public void setPasswordHash(String passwordHash) { this.passwordHash = passwordHash; }

	  

	  @UserRoles
	  @ManyToMany(targetEntity = Rol.class)
	  @JoinTable(name = "UserRoles", 
	    joinColumns = @JoinColumn(name = "UserId"),
	    inverseJoinColumns = @JoinColumn(name = "RoleId"))
	  public Set<Rol> getRoles() { return roles; }

	  public void setRoles(Set<Rol> roles) { this.roles = roles; }
}